﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Centido.Management.ConsoleManager
{
    /// <summary>
    ///   A parameter of a console command.
    /// </summary>
    internal class CommandParameter
    {
        /// <summary>
        ///   The parameter values.
        /// </summary>
        private readonly List<string> _values = new List<string>();


        /// <summary>
        ///   Creates a new instance of the <see cref="CommandParameter"/> class
        /// with the specified parameter name.
        /// </summary>
        /// <param name="parameterName">The parameter name.</param>
        /// <exception cref="ArgumentNullException">Thrown when the value of <paramref name="parameterName"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when the value of <paramref name="parameterName"/> is an empty string.</exception>
        public CommandParameter(string parameterName)
        {
            if (parameterName == null)
                throw new ArgumentNullException("parameterName");
            if (string.IsNullOrEmpty(parameterName))
                throw new ArgumentException("The parameter name cannot be empty.");

            Name = parameterName;
        }


        /// <summary>
        ///   Gets the command parameter name.
        /// </summary>
        public string Name { get; private set; }


        /// <summary>
        ///   Gets the first value of the parameter.
        /// </summary>
        public string FirstValue 
        {
            get { return _values.FirstOrDefault(); }
        }


        /// <summary>
        ///   Gets the list of parameter values.
        /// </summary>
        public ICollection<string> Values
        {
            get { return _values; }
        }


        /// <summary>
        ///   Adds a new parameter value.
        /// </summary>
        /// <param name="value">The new value.</param>
        /// <exception cref="ArgumentNullException">Thrown when the value of <paramref name="value"/> is null.</exception>
        public void AddValue(string value)
        {
            if (value == null)
                throw new ArgumentNullException("value");

            if (!_values.Contains(value))
                _values.Add(value);
        }
    }
}
